package com.rockcent.service.impl;

import com.rockcent.common.domain.enumclass.Whether;
import com.rockcent.mall.lib.domain.MerchantGiftPacket;
import com.rockcent.mall.lib.domain.enumclass.GiftPacketStatus;
import com.rockcent.mall.lib.repository.MerchantGiftPacketRepository;
import com.rockcent.service.MerchantGiftPacketSrv;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 礼包管理接口
 * Created by DK on 16/11/28.
 */
@Service
public class MerchantGiftPacketSrvImpl implements MerchantGiftPacketSrv {

    @Autowired
    private MerchantGiftPacketRepository merchantGiftPacketRepository;

    @Override
    public void updateMarketGiftPacket(Long id, GiftPacketStatus status, Whether whether) {
        List<MerchantGiftPacket> merchantGiftPacketList = merchantGiftPacketRepository.findByMarketId(id);
        merchantGiftPacketList.forEach(giftPacket ->{
            if (status != null) {
                giftPacket.setStatus(status);
            }
            if (whether != null) {
                giftPacket.setIsDelete(whether);
            }
            merchantGiftPacketRepository.save(giftPacket);
        });
    }
}
